unit MapEngine;

interface

uses
  System.Collections, System.IO, Map;

type
  TMapEngine = class
  private
    { Private Declarations }
    maps : ArrayList;
    function GetNumberOfLevels() : Integer;
  public
    property NumberOfLevels : Integer read GetNumberOfLevels;
    constructor Create;
    procedure LoadMaps();
    function GetMapForLevel(level : Integer) : TMap;
  end;

implementation

constructor TMapEngine.Create;
begin
  inherited Create;

  self.maps := ArrayList.Create();
  self.LoadMaps();
end;

function TMapEngine.GetNumberOfLevels : Integer;
begin
  Result := self.maps.Count;
end;

function TMapEngine.GetMapForLevel(level: Integer) : TMap;
var
  map : TMap;
  i: Integer;

begin
  for i := 0 to self.maps.Count - 1 do
  begin
    map := self.maps[i] as TMap;
    if (map.Level = level) then
    begin
      result := map;
      break;
    end;
  end;
end;

procedure TMapEngine.LoadMaps();
var
  files : array of String;
  i : integer;
begin
  files := Directory.GetFiles('Maps\', '*.xml');
  
  for i := 0 to length(files)- 1 do
  begin
    self.maps.Add(TMap.Create(FileInfo.Create(files[i]).FullName));
  end;
end;

end.
